<?php
/**
 * VoteActiveInfo.class.php
 *
 * @author camfee <camfee@foxmail.com>
 * @date   18-1-2 下午9:17
 */

namespace Center;

use Common\ModuleBase;
use Common\Bridge;

class VoteActiveInfo extends ModuleBase
{
    protected static $_conf = [
        'db' => [
            'w' => Bridge::DB_CENTER_W,
            'r' => Bridge::DB_CENTER_R
        ],
        'table' => 'VoteActiveInfo',
        'fields' => [
            'Id' => self::VAR_TYPE_KEY,
            'ActiveId' => self::VAR_TYPE_INT,
            'ShopId' => self::VAR_TYPE_INT,
            'UserId' => self::VAR_TYPE_INT,
            'VoteNum' => self::VAR_TYPE_INT,
            'RewardStatus' => self::VAR_TYPE_INT,
            'RewardRank' => self::VAR_TYPE_INT,
            'RewardNum' => self::VAR_TYPE_INT,
            'UpdateTime' => self::VAR_TYPE_STRING,
            'CreateTime' => self::VAR_TYPE_STRING,
        ],
        'mc' => Bridge::MEMCACHE_DEFAULT,
        // 可选, MC KEY, "KeyName:%d", %d会用主键ID替代
        'mckey' => 'VoteActiveInfo:%d',
        // 可选, 超时时间, 默认不过期
        'mctime' => 86400,
    ];

    /**
     * 检查投票
     *
     * @param $active_id
     * @param $shop_id
     * @param $user_id
     * @return array
     */
    public static function checkVote($active_id, $shop_id, $user_id)
    {
        $where = [
            'ActiveId' => $active_id,
            'ShopId' => $shop_id,
            'UserId' => $user_id
        ];
        $info = self::getList($where, 0, 1);

        return !empty($info['data']) ? $info['data'][0] : [];
    }

    /**
     * @see ModuleBase::add() 新增
     * @see ModuleBase::update() 更新
     * @see ModuleBase::getInfoByIds() 按id查询
     * @see ModuleBase::getList() 条件查询
     * @see ModuleBase::delete() 删除
     */

}